# -*- coding: utf-8 -*-

"""
controller for task
"""

from framework.controller import Controller
from models.task import TaskModel
from sync import DataSync
import time

class TaskCtrl(Controller):
    """task list"""
    def __init__(self, application, request, **kwargs):
        """init"""
        super(TaskCtrl, self).__init__(application, request, **kwargs)

    def get(self):
        """task get handler"""
        msg = dict(err=1, msg=u'未有数据同步记录')
        m = TaskModel()
        # get the sync list from mongodb
        sync = m.get_sync()
        if not sync:
            self.ajax_out(**msg)
            return
        lang = DataSync()
        msg = dict(err=0, info=lang.lang.get(sync['progress']),
                   progress=lang.proc.get(sync['progress']), time=sync['sync_time'])
        self.ajax_out(**msg)
        return